package com.bo.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bo.enity.RecipeRatio;
import com.bo.mapper.RecipeRatioMapper;
import com.bo.service.IRecipeRatioService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: outes-boot
 * @Date:   2024-11-27
 * @Version: V1.0
 */
@Service
@DS("sp1")
public class SP1RecipeRatioServiceImpl extends ServiceImpl<RecipeRatioMapper, RecipeRatio> implements IRecipeRatioService {

    @Resource
    private RecipeRatioMapper recipeRatioMapper;

    @Override
    @DS("sp1")
    public Integer getMaxId() {
        return recipeRatioMapper.getMaxId();
    }

    @Override
    @DS("sp1")
    public RecipeRatio getByRatioCode(String ratioCode) {
        QueryWrapper<RecipeRatio> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(RecipeRatio::getRecipeName, ratioCode);
        queryWrapper.lambda().orderByDesc(RecipeRatio::getRecipeID);
        List<RecipeRatio> recipeRatios = recipeRatioMapper.selectList(queryWrapper);
        if ( recipeRatios!= null && !recipeRatios.isEmpty()) {
            return recipeRatios.get(0);
        }
        return null;
    }
}
